﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EF6CodeFirstMySQL.Model
{
    public class DataModelContext : DbContext
    {
        public DataModelContext()
            : base("DataModelContext")//web.config中connectionstring的名字
        {
        }

        public DbSet<Contract> Contracts { get; set; }
        public DbSet<DeliveryNote> DeliveryNotes { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //指定单数形式的表名
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            //物理表名添加xx前綴
            modelBuilder.Types().Configure(f => f.ToTable("xx" + f.ClrType.Name));
        }
    }

}
